#include<iostream>
#include<pthread.h>
#include"Ringqueue.hpp"
#include<functional>
#include"Task.hpp"
#include<unistd.h>
using namespace std;
using task_t=function<void()>;
void* Consumer(void* args)
{
    Ringqueue<task_t>* rq=static_cast<Ringqueue<task_t>*>(args);
    while(true)
    {
        //sleep(1);
        task_t t;
        rq->Pop(&t);
        t();
    }

}
void* Productor(void* args)
{
    Ringqueue<task_t>* rq=static_cast<Ringqueue<task_t>*>(args);
    while(true)
    {
        sleep(1);
        rq->Push(func);
    }
}
int main()
{
    pthread_t c1,c2,p1,p2,p3;
    Ringqueue<task_t>* rq=new Ringqueue<task_t>(5);
    pthread_create(&c1,nullptr,Consumer,rq);
    pthread_create(&c2,nullptr,Consumer,rq);
    pthread_create(&p1,nullptr,Productor,rq);
    pthread_create(&p2,nullptr,Productor,rq);
    pthread_create(&p3,nullptr,Productor,rq);

    pthread_join(c1,nullptr);
    pthread_join(c2,nullptr);
    pthread_join(p1,nullptr);
    pthread_join(p2,nullptr);
    pthread_join(p3,nullptr);
    return 0;
}